package com.kj.platformlogistics.home.adapter;

import android.media.MediaMetadata;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kj.platformlogistics.R;
import com.kj.platformlogistics.home.model.SolicilationedModel;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class WaitSolicilationDetailAdapter extends BaseQuickAdapter<SolicilationedModel.ResultDTO.PageDTO.OrderDetailListDTO, BaseViewHolder> {
    private StringBuilder strSku=null;

    public WaitSolicilationDetailAdapter(@Nullable List<SolicilationedModel.ResultDTO.PageDTO.OrderDetailListDTO> data) {
        super(R.layout.item_wait_solicilation_detail, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SolicilationedModel.ResultDTO.PageDTO.OrderDetailListDTO item) {
        ImageView ivGoodsImg=helper.getView(R.id.ivGoodsImg);
        Glide.with(mContext).load(item.getCommodityMainPhoto())
                .placeholder(R.mipmap.default_image)
                .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
                .into(ivGoodsImg);
        helper.setText(R.id.tvGoodsName,item.getCommodityName());

        helper.setText(R.id.tvPrice,"￥"+item.getCommodityPrice());
        helper.setText(R.id.tvNum,"数量：x"+item.getNumber());
        strSku=new StringBuilder();
        if (item.getCommoditySpData()!=null){
            try {
                JSONArray jsonArray = new JSONArray(item.getCommoditySpData());
                for(int i=0;i<jsonArray.length();i++){
                    JSONObject jsonObject=jsonArray.getJSONObject(i);
                    strSku.append(" "+jsonObject.getString("value"));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        helper.setText(R.id.tvSku,"规格："+strSku);
    }
}
